#!/bin/bash

#某个日期在一年当中的天数,全局变量
num_date_days=0
#某一个年份全年的天数
num_year_days=0
#两个日期相差的天数
diff_between_dates=0
#当前日期
today=`date "+%Y-%m-%d"`
#需要处理的日期间隔期限
days_diff_standard=3
#打包得到的目标文件名
REALEASE_TARGETFILENAME="/opt/MyVMBackUp_$today.zip"

. /usr/bin/mycommand/mycolor
MODIFYWEBRTCPATH='/root/Projects/webrtc-checkout/src'
ORIGINWEBRTCPATH='/root/OpenMind/webrtc-checkout/src'

WORKPATH=`pwd`
mkdir -p webrtc_diffs/modify
mkdir -p webrtc_diffs/origin
function recurse_search()
{
  cd "$1"
  for file in * ; do
    CURPATH=`pwd`
    if [[ -d "$file" ]] ; then
      if [ "$file" != "soup" -a "$file" != "webrtc-study" ];then
        fullfilename="$CURPATH/$file"
        recurse_search "$fullfilename"
	  fi
    fi
    if [[ -f "$file" ]] ; then
        if [[ -z ${file##*.} ]];then
            logdebug "找到没有后缀的文件:$file"
        fi
#         logdebug "file is $file"
        if [[ ${file##*.} = 'h' ]] || [[ ${file##*.} = 'hpp' ]] || [[ ${file##*.} = 'hxx' ]] || [[ ${file##*.} = 'c' ]] || [[ ${file##*.} = 'cpp' ]] || [[ ${file##*.} = 'cc' ]] || [[ ${file##*.} = 'cxx' ]] || [[ ${file##*.} = 'm' ]] || [[ ${file##*.} = 'mm' ]] || [[ ${file##*.} = 'java' ]] || [[ ${file##*.} = 'py' ]] || [[ ${file##*.} = 'gn' ]]
        then
            fullfilename="$CURPATH/$file"  
            relfilename=${fullfilename//$MODIFYWEBRTCPATH/}
            relfilepath=${CURPATH//$MODIFYWEBRTCPATH/}
            otherfullfilename="$ORIGINWEBRTCPATH/$relfilename"
            md5sumval=`md5sum $fullfilename| awk '{print $1}'`
#             logdebug "找到文件 $relfilename,md5值:$md5sumval,原始文件:$otherfullfilename"
            if [[ -f $otherfullfilename ]]; then
                    othermd5sumval=`md5sum $otherfullfilename | awk '{print $1}'`
                    if [[ "$othermd5sumval" != "$md5sumval" ]];then
                        logwarn "找到不同的文件: $relfilename $relfilepath "
                        mkdir -p $WORKPATH/webrtc_diffs/modify/$relfilepath
                        mkdir -p $WORKPATH/webrtc_diffs/origin/$relfilepath
                        cp -f $fullfilename  $WORKPATH/webrtc_diffs/modify/$relfilepath
                        cp -f $otherfullfilename  $WORKPATH/webrtc_diffs/origin/$relfilepath
                    fi
            else
                logwarn "找到原始目录不存在的文件: $relfilename $relfilepath "
                mkdir -p $WORKPATH/webrtc_diffs/modify/$relfilepath
                cp -f $fullfilename  $WORKPATH/webrtc_diffs/modify/$relfilepath
            fi
        fi
    fi
  done
  if [[ "$1" != "." ]] ; then
    cd ..
  fi
}

recurse_search $MODIFYWEBRTCPATH
